package com.deyuanyun.pic.ctrl.controller.vo.exinsp;

import com.deyuanyun.pic.common.spring.SpringAppliction;
import com.deyuanyun.pic.common.util.NumberUtil;
import com.deyuanyun.pic.common.util.format.DateFormat;
import com.deyuanyun.pic.ctrl.domain.EqptCptestStation;
import com.deyuanyun.pic.ctrl.domain.ExinspOclpoint;
import com.deyuanyun.pic.ctrl.enumeration.CurrentFerenceEnum;
import com.deyuanyun.pic.ctrl.enumeration.RepairStateEnum;
import com.deyuanyun.pic.ctrl.enumeration.RepairSuggestedEnum;
import com.deyuanyun.pic.ctrl.service.EQPTBaseService;
import com.deyuanyun.pic.pipe.controller.vo.BaseVOUtil;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.deyuanyun.pic.settings.support.biz.PipeLineUtil;
import com.github.pagehelper.Page;

import java.math.BigDecimal;

/**
 * 外涂层漏损点信息表
 */
public class ExinspOclpointVO extends ExinspBaseVO<ExinspOclpoint> {

    // 管道名称
    private String pipeLineName;
    // 漏损点编号
    private String customNumber;
    // 绝对距离
    private BigDecimal mileage;
    // 附近测试桩
    private String nagm;
    // 附近测试桩距离
    private BigDecimal nagmMileage;
    // 位置描述
    private String locationDescription;
    // 埋深（m）
    private BigDecimal buriedDepth;
    // dB值
    public Long dbValue;
    // IR%
    private String irValue;
    // 通电电位(mV)
    public Long onPotential;
    // 断电电位(mV)
    public Long offPotential;
    // 杂散电流干扰程度_交流干扰（强、中、弱）
    private String acInterference;
    // 杂散电流干扰程度_直流干扰（强、中、弱）
    private String dcInterference;
    // 漏损点等级
    private Short faultGrade;
    // 修复建议（立即维修、计划维修、暂不维修、监控）REPAIR_SUGGESTED
    private String repairSuggestion;
    // 最迟修复时间
    private String latestRepairTime;
    // 修复状态（已修复、未修复、修复中、难以修复）
    private String repairState;
    // 检测日期
    private String testingDate;
    // 检测单位
    private String testingCompany;

    public String getPipeLineName() {
        return pipeLineName;
    }

    public void setPipeLineName(String pipeLineName) {
        this.pipeLineName = pipeLineName;
    }

    public String getCustomNumber() {
        return customNumber;
    }

    public void setCustomNumber(String customNumber) {
        this.customNumber = customNumber;
    }

    public BigDecimal getMileage() {
        return mileage;
    }

    public void setMileage(BigDecimal mileage) {
        this.mileage = mileage;
    }

    public String getNagm() {
        return nagm;
    }

    public void setNagm(String nagm) {
        this.nagm = nagm;
    }

    public BigDecimal getNagmMileage() {
        return nagmMileage;
    }

    public void setNagmMileage(BigDecimal nagmMileage) {
        this.nagmMileage = nagmMileage;
    }

    public String getLocationDescription() {
        return locationDescription;
    }

    public void setLocationDescription(String locationDescription) {
        this.locationDescription = locationDescription;
    }

    public BigDecimal getBuriedDepth() {
        return buriedDepth;
    }

    public void setBuriedDepth(BigDecimal buriedDepth) {
        this.buriedDepth = buriedDepth;
    }

    public Long getDbValue() {
        return dbValue;
    }

    public void setDbValue(Long dbValue) {
        this.dbValue = dbValue;
    }

    public String getIrValue() {
        return irValue;
    }

    public void setIrValue(String irValue) {
        this.irValue = irValue;
    }

    public Long getOnPotential() {
        return onPotential;
    }

    public void setOnPotential(Long onPotential) {
        this.onPotential = onPotential;
    }

    public Long getOffPotential() {
        return offPotential;
    }

    public void setOffPotential(Long offPotential) {
        this.offPotential = offPotential;
    }

    public String getAcInterference() {
        return acInterference;
    }

    public void setAcInterference(String acInterference) {
        this.acInterference = acInterference;
    }

    public String getDcInterference() {
        return dcInterference;
    }

    public void setDcInterference(String dcInterference) {
        this.dcInterference = dcInterference;
    }

    public Short getFaultGrade() {
        return faultGrade;
    }

    public void setFaultGrade(Short faultGrade) {
        this.faultGrade = faultGrade;
    }

    public String getRepairSuggestion() {
        return repairSuggestion;
    }

    public void setRepairSuggestion(String repairSuggestion) {
        this.repairSuggestion = repairSuggestion;
    }

    public String getLatestRepairTime() {
        return latestRepairTime;
    }

    public void setLatestRepairTime(String latestRepairTime) {
        this.latestRepairTime = latestRepairTime;
    }

    public String getRepairState() {
        return repairState;
    }

    public void setRepairState(String repairState) {
        this.repairState = repairState;
    }

    public String getTestingDate() {
        return testingDate;
    }

    public void setTestingDate(String testingDate) {
        this.testingDate = testingDate;
    }

    public String getTestingCompany() {
        return testingCompany;
    }

    public void setTestingCompany(String testingCompany) {
        this.testingCompany = testingCompany;
    }

    EQPTBaseService eqptBaseService = SpringAppliction.getBean(EQPTBaseService.class);

    public void fromDomain(ExinspOclpoint domain) {

        // 管道名称
        this.pipeLineName = PipeLineUtil.getPipeLineName(domain.getPipeLineId());
        // 漏损点编号
        this.customNumber = domain.getCustomNumber();
        // 绝对距离（m）
        this.mileage = NumberUtil.toMeter(domain.getMileage());
        // 附近测试桩
        EqptCptestStation eqptCptestStation = eqptBaseService.queryObjectByPrimaryKey(EqptCptestStation.class, domain.getNagm());
        this.nagm = eqptCptestStation==null ? null : eqptCptestStation.getCustomNumber();
        // 附近测试桩距离（m）
        this.nagmMileage = NumberUtil.toMeter(domain.getNagmMileage());
        // 位置描述
        this.locationDescription = domain.getLocationDescription();
        // 埋深（m）
        this.buriedDepth = domain.getBuriedDepth();
        // dB值
        this.dbValue = domain.getDbValue();
        // IR%
        this.irValue = domain.getIrValue();
        // 通电电位(mV)
        this.onPotential = domain.getOnPotential();
        // 断电电位(mV)
        this.offPotential = domain.getOffPotential();
        // 杂散电流干扰程度_交流干扰（强、中、弱）
        this.acInterference = CurrentFerenceEnum.getLabelBycode(domain.getAcInterference());
        // 杂散电流干扰程度_直流干扰（强、中、弱）
        this.dcInterference = CurrentFerenceEnum.getLabelBycode(domain.getDcInterference());
        // 漏损点等级
        this.faultGrade = domain.getFaultGrade();
        // 修复建议（立即维修、计划维修、暂不维修、监控）REPAIR_SUGGESTED
        this.repairSuggestion = CodeUtil.getName(domain.getRepairSuggestion());
        // 最迟修复时间
        this.latestRepairTime = DateFormat.format(domain.getLatestRepairTime());
        // 修复状态（已修复、未修复、修复中、难以修复）
        this.repairState =  RepairStateEnum.getLabel(domain.getRepairState());
        // 检测日期
        this.testingDate = DateFormat.format(domain.getTestingDate());
        // 检测单位
        this.testingCompany = domain.getTestingCompany();

        super.fromDomain(domain.getId(), domain.getRecorder(), domain.getRecordTime(), domain.getRemarks());
    }

    public Page<ExinspOclpointVO> fromDomainList(Page<ExinspOclpoint> domainList) {

        Page<ExinspOclpointVO> list = new Page<ExinspOclpointVO>();
        for (ExinspOclpoint exinspOclpoint : domainList) {
            ExinspOclpointVO exinspOclpointVO = new ExinspOclpointVO();
            exinspOclpointVO.fromDomain(exinspOclpoint);
            list.add(exinspOclpointVO);
        }
        BaseVOUtil.converterPage(domainList, list);
        return list;
    }
}